use std::sync::mpsc::sync_channel;
use std::thread;

fn main() {
    //创建一个通道
    let (tx, rx) = sync_channel(3);
    //启动3个生产者
    for _ in 0..3 {
        let tx = tx.clone();
        // cloned tx dropped within thread
        thread::spawn(move || tx.send("ok").unwrap());
    }
    //接收生产者的消息
    while let Ok(msg) = rx.recv() {
        println!("{msg}");
    }
    println!("mpsc_example4 completed");
}
